home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / misc / VMM_src.lha / VMM / tools / ReadMMUConfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-16  |  6.0 KB  |  258 lines

  1. /* This program generates a listing of the current MMU setup and writes
  2.  * it to the files ENVARC:VMM_MMU.config and ENV:VMM_MMU.config.
  3.  * The file ENV:VMM_MMU.config is read by VMM upon startup to initialize
  4.  * the MMU table the same way it is when running without VMM.
  5.  */
  6.  
  7. #include <exec/types.h>
  8. #include <exec/execbase.h>
  9. #include <dos/dos.h>
  10. #include <clib/exec_protos.h>
  11. #include <clib/dos_protos.h>
  12. #include <stdio.h>
  13. #ifdef __GNUC__
  14. #include "../protos.h"
  15. #else
  16. #include "/protos.h"
  17. #endif
  18.  
  19. #define ENV_FILENAME "ENV:VMM_MMU.config"
  20. #define ENVARC_FILENAME "ENVARC:VMM_MMU.config"
  21.  
  22. struct RegionDescr
  23.   {
  24.   ULONG log_from,
  25.         log_to,
  26.         phys_from,
  27.         phys_to;
  28.   ULONG attr;
  29.   };
  30.  
  31. #define TYPE_INVALID 0
  32. #define TYPE_RESIDENT 1
  33. #define TYPE_MASK 0x3
  34. #define WP 0x4
  35. #define CM_MASK 0x60
  36. #define TTHIT   0x8           /* Misused USED bit */
  37.  
  38. ULONG PageSize;
  39.  
  40. /* Valid attributes differ for different processor types:
  41.  * For the 68851 and 68030 the following bits are valid:
  42.  *   write-protected, page type and cache mode.
  43.  * For the 68040 and 68060 the same bits are valid but the cache mode is
  44.  * represented by two bits.
  45.  */
  46.  
  47. FILE *EnvFile,
  48.      *EnvArcFile;
  49. BOOL verbose = FALSE;
  50. BOOL debug = FALSE;
  51.  
  52. ULONG (*GenDescr) (ULONG);
  53.  
  54. extern struct ExecBase *SysBase;
  55.  
  56. /************************************************************************/
  57.  
  58. void WriteRegion (struct RegionDescr *reg)
  59.  
  60. {
  61. if ((reg->attr & TYPE_MASK) == TYPE_INVALID)
  62.   {
  63.   /* This region is invalid */
  64.   if (debug)
  65.     {
  66.     printf ("Region is marked as invalid\n");
  67.     printf ("Log address start: %08lx\n", reg->log_from);
  68.     printf ("Log address end  : %08lx\n", reg->log_to);
  69.     printf ("Phys address start: %08lx\n", reg->phys_from);
  70.     printf ("Phys address end  : %08lx\n", reg->phys_to);
  71.     printf ("Attributes are %04lx\n", reg->attr);
  72.     }
  73.   return;
  74.   }
  75.  
  76. if ((reg->phys_from == reg->phys_to) &&
  77.     (reg->log_from  != reg->log_to))
  78.   {
  79.   /* This region is mapped to a single page. Treat it as if it
  80.    * was invalid.
  81.    */
  82.   if (debug)
  83.     {
  84.     printf ("Region maps to a single page\n");
  85.     printf ("Log address start: %08lx\n", reg->log_from);
  86.     printf ("Log address end  : %08lx\n", reg->log_to);
  87.     printf ("Phys address start: %08lx\n", reg->phys_from);
  88.     printf ("Phys address end  : %08lx\n", reg->phys_to);
  89.     printf ("Attributes are %04lx\n", reg->attr);
  90.     }
  91.   return;
  92.   }
  93.  
  94. if (verbose)
  95.   printf ("Logical address %08lx maps to %08lx, length %08lx, type %04lx\n",
  96.           reg->log_from, reg->phys_from, 
  97.           reg->log_to - reg->log_from + PageSize, reg->attr);
  98.  
  99. fprintf (EnvFile, "%08lx %08lx %08lx %04lx\n",
  100.          reg->log_from, reg->phys_from,
  101.           reg->log_to - reg->log_from + PageSize, reg->attr);
  102.  
  103. fprintf (EnvArcFile, "%08lx %08lx %08lx %04lx\n",
  104.          reg->log_from, reg->phys_from,
  105.           reg->log_to - reg->log_from + PageSize, reg->attr);
  106. }
  107.  
  108. /************************************************************************/
  109.  
  110. void WriteMMUTable (void)
  111.  
  112. {
  113. ULONG current_log_addr = 0;
  114. ULONG current_phys_addr;
  115. ULONG current_attr = 0;
  116. struct RegionDescr current_region;
  117.  
  118. current_region.log_from  = 0;
  119. current_region.log_to    = 0;
  120. current_region.phys_from = 0;
  121. current_region.phys_to   = 0;
  122. current_region.attr      = 0;
  123.  
  124. do
  125.   {
  126.   current_phys_addr = (*GenDescr) (current_log_addr);
  127.   if (debug)
  128.     printf ("Descriptor returned for address %08lx: %08lx\n", current_log_addr,
  129.             current_phys_addr);
  130.  
  131.   current_attr = current_phys_addr & (TYPE_MASK | WP | CM_MASK | TTHIT);
  132.   current_phys_addr &= ~(PageSize - 1);
  133.  
  134.   if (current_region.attr != current_attr || 
  135.       current_phys_addr < current_region.phys_to ||
  136.       current_phys_addr > current_region.phys_to + PageSize)
  137.     {
  138.     WriteRegion (¤t_region);
  139.     current_region.log_from  = current_log_addr;
  140.     current_region.log_to    = current_log_addr;
  141.     current_region.phys_from = current_phys_addr;
  142.     current_region.phys_to   = current_phys_addr;
  143.     current_region.attr      = current_attr;
  144.     }
  145.   else
  146.     {
  147.     current_region.log_to  = current_log_addr;
  148.     current_region.phys_to = current_phys_addr;
  149.     }
  150.  
  151.   current_log_addr += PageSize;
  152.   } while (current_log_addr != 0L);          /* overflowed once */
  153.  
  154. WriteRegion (¤t_region);
  155. }
  156.  
  157. /************************************************************************/
  158.  
  159. void main (int argc, char *argv [])
  160.  
  161. {
  162. int i;
  163.  
  164. for (i = 1; i < argc; i++)
  165.   {
  166.   if (FindArg ("VERBOSE/S", argv [i]) != -1)
  167.     {
  168.     verbose = TRUE;
  169.     printf ("Verbose mode\n");
  170.     }
  171.   else if (FindArg ("DEBUG/S", argv [i]) != -1)
  172.     {
  173.     debug = TRUE;
  174.     verbose = TRUE;
  175.     printf ("Debug mode enabled\n");
  176.     }
  177.   else
  178.     {
  179.     fprintf (stderr, "Usage: %s VERBOSE/S DEBUG/S\n", argv [0]);
  180.     return;
  181.     }
  182.   }
  183.  
  184. if ((EnvFile = fopen (ENV_FILENAME, "w")) == NULL)
  185.   {
  186.   fprintf (stderr, "Could not open %s for writing MMU table\n", ENV_FILENAME);
  187.   return;
  188.   }
  189.  
  190. if ((EnvArcFile = fopen (ENVARC_FILENAME, "w")) == NULL)
  191.   {
  192.   fprintf (stderr, "Could not open %s for writing MMU table\n", ENVARC_FILENAME);
  193.   fclose (EnvFile);
  194.   return;
  195.   }
  196.  
  197. /* Determine processor type */
  198. if (SysBase->AttnFlags & AFF_68040)
  199.   {
  200.   if (Is68060 ())
  201.     {
  202.     if (verbose)
  203.       printf ("68060 detected\n");
  204.     GenDescr = GenDescr60;
  205.     PageSize = GetPageSize60 ();
  206.     }
  207.   else
  208.     {
  209.     if (verbose)
  210.       printf ("68040 detected\n");
  211.     GenDescr = GenDescr40;
  212.     PageSize = GetPageSize40 ();
  213.     }
  214.   }
  215. else if (SysBase->AttnFlags & AFF_68030)
  216.   {
  217.   if (verbose)
  218.     printf ("68030 detected\n");
  219.   GenDescr = GenDescr30;
  220.   PageSize = GetPageSize30 ();
  221.   }
  222. else if ((SysBase->AttnFlags & AFF_68020) && MMU68851 ())
  223.   {
  224.   if (verbose)
  225.     printf ("68020+68851 detected\n");
  226.   GenDescr = GenDescr851;
  227.   PageSize = GetPageSize30 ();
  228.   }
  229. else
  230.   {
  231.   fprintf (stderr, "You need a MMU to use VMM\n");
  232.   fclose (EnvFile);
  233.   fclose (EnvArcFile);
  234.   return;
  235.   }
  236.  
  237. if (PageSize < 4096)
  238.   PageSize = 4096;
  239.  
  240. WriteMMUTable ();
  241.  
  242. fclose (EnvFile);
  243. fclose (EnvArcFile);
  244.  
  245. if (verbose)
  246.   printf ("MMU configuration written to " ENV_FILENAME " and " ENVARC_FILENAME "\n");
  247. }
  248.  
  249. void PrintDebugMsg (void)
  250.  
  251. {
  252. }
  253.  
  254. void OrigColdReboot (void)
  255.  
  256. {
  257. }
  258.